package com.zxl.live.screen.call.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdSize;
import com.zxl.live.screen.R;
import com.zxl.live.screen.ads.banner.AdmobBannerProxy;
import com.zxl.live.screen.call.helper.ThemeHelper;
import com.zxl.live.screen.call.ui.widget.ThemePreviewWindow;
import com.zxl.live.screen.screen.constant.ISharedPreferences;
import com.zxl.live.screen.screen.constant.ScreenSetting;
import com.zxl.live.screen.screen.ui.widget.SettingItemView;
import com.zxl.live.tools.analytics.Event;
import com.zxl.live.tools.base.BaseAppCompatActivity;
import com.zxl.live.tools.track.StatisticsConstant;
import com.zxl.live.tools.track.StatisticsType;

/**
 * Created by Administrator on 2017/12/11.
 */

public class CallThemeSettingActivity extends BaseAppCompatActivity implements View.OnClickListener {

    private SettingItemView mScreenSwitchView;

    private ThemePreviewWindow mThemePreviewWindow;

    private LinearLayout mAdsLayout;

    private  AdmobBannerProxy mBannerProxy;

    private AdListener mAdListener = new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mAdsLayout.setVisibility(View.VISIBLE);
            mBannerProxy.showAds(mAdsLayout);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_theme_setting);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(this);
        findViewById(R.id.more).setOnClickListener(this);
        mThemePreviewWindow = (ThemePreviewWindow) findViewById(R.id.preview_window);
        mThemePreviewWindow.play(ThemeHelper.type, ThemeHelper.flashPath);
        mThemePreviewWindow.setDefaultNumber();

        mScreenSwitchView = (SettingItemView) findViewById(R.id.screen_switch);
        mScreenSwitchView.setOnClickListener(this);

        mAdsLayout = (LinearLayout) findViewById(R.id.ads_layout);
        mBannerProxy = new AdmobBannerProxy(Event.ADS_CALL_SETTINGS);
        mBannerProxy.setProxy(mAdListener);
        mBannerProxy.loadAds(this, AdSize.BANNER, "ca-app-pub-1417586053260517/1164533744");
    }

    @Override
    protected void onResume() {
        super.onResume();
        mScreenSwitchView.setChecked(ScreenSetting.sCallFlashSwitch);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mThemePreviewWindow.stop();
        mBannerProxy.recycle();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.more:
                StatisticsType.CALL_FLASH.upload(this, StatisticsConstant.Event.STATUS, "click_more");
                finish();
                break;
            case R.id.screen_switch:
                mScreenSwitchView.toggle();
                boolean checked = mScreenSwitchView.isChecked();
                ScreenSetting.saveLockerSettings(ISharedPreferences.SETTINGS_CALL_FLASH_SWITCH, checked);
                StatisticsType.CALL_FLASH.upload(this, StatisticsConstant.Event.STATUS, "click_switch_" + checked);
                break;
            default:
                onBackPressed();
                break;
        }

    }
}
